package validators;

import java.util.ResourceBundle;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("validators.RequestResourceValidator")
public class RequestResourceValidator implements Validator {

	ResourceBundle bundle = ResourceBundle.getBundle(
			"languageSettings.language", FacesContext.getCurrentInstance()
					.getViewRoot().getLocale());
	
	/**
	 * @author Katona Gabor
	 * @version 1.0
	 * @param FacesContext context, UIComponent component, Integer value
	 * Verifies if the quantity inserted is greater than 0
	 */
	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value)
			throws ValidatorException {
		// TODO Auto-generated method stub
		if (((Integer) value) < 1) {
			HtmlInputText inputText = (HtmlInputText) component;
			FacesMessage fMessage = new FacesMessage(inputText.getLabel()
					+ bundle.getString("Validators_RequestResourceValidator_Error"));
			throw new ValidatorException(fMessage);
		}
	}

}
